//
//  SinaHomeViewController.swift
//  Sina
//
//  Created by 星仔 on 2017/2/23.
//  Copyright © 2017年 xingZai. All rights reserved.
//

import UIKit

private let cellId = "homeCell"

class SinaHomeViewController: SinaBaseController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
    }
    
    var dataList = [NSString]()
    
 //MARK:loadData
    //,Method does not override any method from its superclass（说明你的方法写在class之外了，除去extension和class外，一般它不认识）
    override func setupData(){
        
        SinaNetWorksManager.shareNetWorkManager.statusList { (json, isSuccess) in
            print("\(json),\(isSuccess)")
        }
        //模拟延时下拉刷新
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            for i in 0..<20{
                if self.isPull {
                    self.dataList.append("上拉\(i)" as NSString)
                }else{
                   
                    self.dataList.insert(i.description  as NSString, at: 0)
                }
                
            }
            self.refresh?.endRefreshing()
            self.isPull = false
            self.tableView?.reloadData()
        }
        
        
    }
 //MARK:touch response
    //FIXME:buttonclick
    func buttonclick(){
        
        navigationController?.pushViewController(TestViewController(), animated: true)
    }
}
//MARK:
extension SinaHomeViewController{
    
   override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
     return dataList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = dataList[indexPath.row] as String
        return cell
    }
    
}
//MARK:设置UI
extension SinaHomeViewController{
    
    override func setupUI() {
        super.setupUI()
        
        navBarItems.rightBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(buttonclick), isBack: false)
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
    
}

